<?php

require_once 'db.php';

class Works extends DB {

    public $query;
    public $table_name;
    public $begin;
    public $end;
    public function select_workd() {//phuong thuc
        $this->connects();
        $query = 'SELECT * FROM works LIMIT 0,5';
        $works = $this->query($query);
        return $works;
    }
    public function selects($page = null, $id = null) {
        $this->connects();
        $where = "";
        if (!empty($id))
            $where = "where id=$id";
        $limit = "";
        if (!empty($page))
            $limit = 'limit ' . $begin . ',' . PAGE;
        $begin = ($page - 1) * PAGE;
        $query = "SELECT * FROM $this->table_name $where $limit";
        $result = mysql_query($query);
        $result = mysql_fetch_assoc($result);
        return $result;
    }
    public function update($array = null) {
        $query = " Update works set image='" . $array['img'] . "' where id=" . $array['id'];
        mysql_query($query);
        if (mysql_query($query))
            echo "ok";
        else
            echo "fail";
    }
    public function select($page = null) {
        $this->connects();
        $rows = array();
        $this->begin = ($page - 1) * PAGE;
        $query = "SELECT * FROM $this->table_name LIMIT " . $this->begin . "," .$this->end;
        $result = mysql_query($query);
        while ($row = mysql_fetch_assoc($result))
            $rows[] = $row;
        return $rows;
    }

    public function insert($keywords) {
        $this->connects();
        $query = "INSERT $this->table_name (id, name) values($words[0])";
    }

    public function countWords() {
        $this->connects();
        $rows = array();
        $query = "SELECT * FROM $this->table_name";
        $result = mysql_query($query);
        while ($row = mysql_fetch_assoc($result))
            $rows[] = $row;
        return count($rows);
    }

}
?>
